# -*- coding UTF-8 -*-

import unittest
import os.path

from results_of_one_pair import ResultsOfOnePair
from presenter_mock import PresenterMock
from model.gamestate import *
from model.gamestate import WordGuessResult, Phase


class ResultsOfOnePairTest(unittest.TestCase):
    def setUp(self):
        players = Players([Player('Andrey', []),
                           Player('Boris', []),
                           Player('Charlie', []),
                           Player('Dmitry', [])])
        players.set_next_pair_strategy(NextPairStrategy(players.players))
        hat = Hat([u"SomeThing", u"SomeThingElse"])
        self.game_round = GameRound(0, [], Word(u'player', u'text'),
                                    (players.players[0], players.players[2]))
        self.gamestate = GameState(players, hat, self.game_round,
                                   Phase.RESULTS_OF_ONE_PAIR, [],
                                   None, Settings(0, 20))

        self.l = []
        for i in range(100):
            word_guess_result = WordGuessResult(Word(players.players[1], u"W"),
                                                WordGuessResult.GUESS, 5)
            self.gamestate.game_round.words.append(word_guess_result)
            self.l.append(u"W")

    @unittest.expectedFailure
    def test_ok_button(self):
        self.presenter = PresenterMock(Phase.FROM_TO)
        widget = ResultsOfOnePair(self.gamestate, self.presenter)
        #self.assertEqual(widget.words_added, self.l)
        widget.to_next()
        self.assertEqual(self.gamestate.game_round, None)
        self.assertEqual(len(self.gamestate.rounds), 1)
        self.assertEqual(self.presenter.is_phase_changed, True)
        self.assertEqual(len(self.gamestate.rounds[-1].words), 101)
        self.assertEqual(self.gamestate.rounds[-1].words[-1],
                         WordGuessResult(Word(u'player', u'text'),
                                         WordGuessResult.TIME_OUT, 20))

    def test_empty_hat(self):
        self.gamestate.hat = Hat([])
        self.presenter = PresenterMock(Phase.GAME_RESULTS)
        self.gamestate.game_round.current_word = None
        widget = ResultsOfOnePair(self.gamestate, self.presenter)
        widget.to_next()
        self.assertEqual(self.gamestate.game_round, None)
        self.assertEqual(len(self.gamestate.rounds), 1)
        self.assertEqual(self.presenter.is_phase_changed, True)
        self.assertEqual(len(self.gamestate.rounds[-1].words), 100)


if __name__ == '__main__':
    unittest.main()
